function Communicator(){
    this.parameters = new Array();
    this.parametersLength = 0;
}

//callback é a função que será chamada quando a resposta chegar
Communicator.prototype.sendRequest = function(callbackFunction){
    var request = this.createXmlHttpRequest();

    request.open("GET","ResponseServlet?"+this.getParametersList(),true)
    request.onreadystatechange=function(){
        if(request.readyState == 4 && request.status == 200) { //when it's ready
                        //whether it has a callback function
            if(callbackFunction && typeof callbackFunction === 'function') callbackFunction(request.responseText);
            else Communicator.output = request.responseText;
        }
    };
    request.send(null);
}

Communicator.prototype.createXmlHttpRequest = function(){
    var xmlHttp = null;
    
    if(window.ActiveXObject)
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    else if(window.XMLHttpRequest)
        xmlHttp = new XMLHttpRequest();
    
    return xmlHttp;
}

Communicator.prototype.resetParameters = function(){
    this.parameters = new Array();
    this.parametersLength = 0;
}

Communicator.prototype.addParameter = function(name, value){
    this.parameters.push(name+'='+value);
    this.parametersLength++;
}

Communicator.prototype.getParametersList = function(){
    return this.parameters.join('&');
}

Communicator.prototype.addQueryParameters = function(queryParameters){
    for(var key in queryParameters)
        this.addParameter(key, queryParameters[key]);
}

Communicator.prototype.hasParameters = function(){
    if(this.parametersLength > 0) return true;
    return false;
}